﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BestLifePOS_Core.Data.Fascade;
using BestLifePOS_Core.DomainObjects;

namespace BestLifePOS_PresentationLayer
{
    public partial class frm_Best_Life : Form
    {
        #region Globel variables

        DataTable GvUserDetailsGlobel = new DataTable();
        DataTable GvUserDetails = new DataTable();
        string Gvdis_name = "";
        int Gvflagid = 0;
        List<User> Gvlistuserdetails = new List<User>();
        string Gvterminalid="";
        string Gvbranchname = "";

        #endregion

        public delegate void KeyPressEventHandler(Object senderkey, KeyPressEventArgs ekey);

        public frm_Best_Life(string dis_name,int flag,List<User> listuserdetails,string terminalid,string branchname)
        {
            InitializeComponent();
            
            #region Assign Values To Gvs
            Gvdis_name = dis_name;
            Gvflagid = flag;
            Gvlistuserdetails = listuserdetails;
            Gvterminalid = terminalid;
            Gvbranchname = branchname;
            #endregion

        }

        private void keypressed(Object o, KeyPressEventArgs e)
        {
            //Boolean st=false;
            // The keypressed method uses the KeyChar property to check  
            // whether the ENTER key is pressed.  

            // If the ENTER key is pressed, the Handled property is set to true,  
            // to indicate the event is handled. 
            if (e.KeyChar == (char)Keys.Return)
            {
                e.Handled = true;
               // st=true;
            }
            //return st;
        }
       
        private void txtProductid_TextChanged(object sender, EventArgs e)
        {
            #region Select Detais From ProductID
            GvUserDetails = ProductDAO.GetProductByIdForPos(txtProductid.Text, "0");
            if (GvUserDetails.Rows.Count > 1)
            {
                frmPooupbl Lvfrmpop = new frmPooupbl(txtProductid.Text);
                Lvfrmpop.Show();
            }
            else
            {
                GridFill();
            }
            #endregion
        }

            #region GridFill
        public void GridFill()
        {

            if (txtProductid.Text.Length == 7)
            {
                GvUserDetails = ProductDAO.GetProductByIdForPos(txtProductid.Text, "0");


                for (int i = 0; i <= GvUserDetails.Rows.Count - 1; i++)
                {
                    GvUserDetailsGlobel.Rows.Add(GvUserDetailsGlobel.NewRow());
                    GvUserDetailsGlobel.Rows[GvUserDetailsGlobel.Rows.Count - 1][0] = GvUserDetails.Rows[i][0].ToString();
                    GvUserDetailsGlobel.Rows[GvUserDetailsGlobel.Rows.Count - 1][1] = GvUserDetails.Rows[i][1].ToString();
                    GvUserDetailsGlobel.Rows[GvUserDetailsGlobel.Rows.Count - 1][2] = GvUserDetails.Rows[i][2].ToString();
                    GvUserDetailsGlobel.Rows[GvUserDetailsGlobel.Rows.Count - 1][3] = GvUserDetails.Rows[i][3].ToString();
                    GvUserDetailsGlobel.Rows[GvUserDetailsGlobel.Rows.Count - 1][4] = GvUserDetails.Rows[i][4].ToString();
                    GvUserDetailsGlobel.Rows[GvUserDetailsGlobel.Rows.Count - 1][5] = GvUserDetails.Rows[i][5].ToString();
                    GvUserDetailsGlobel.Rows[GvUserDetailsGlobel.Rows.Count - 1][6] = GvUserDetails.Rows[i][6].ToString();
                    GvUserDetailsGlobel.Rows[GvUserDetailsGlobel.Rows.Count - 1][7] = GvUserDetails.Rows[i][7].ToString();
                }

                gdvselectedproduct.DataSource = GvUserDetailsGlobel;
            }
            else
            {
               
            }

        }
        #endregion

        private void frm_Best_Life_Load(object sender, EventArgs e)
        {
          
            #region GVUserDetailsGlobel--Datatable

            GvUserDetailsGlobel.Columns.Add("Pro_ID");
            GvUserDetailsGlobel.Columns.Add("Pro_Name");
            GvUserDetailsGlobel.Columns.Add("Brand_Name");
            GvUserDetailsGlobel.Columns.Add("Pro_Price");
            GvUserDetailsGlobel.Columns.Add("Ret_Price");
            GvUserDetailsGlobel.Columns.Add("PV");
            GvUserDetailsGlobel.Columns.Add("BV");
            GvUserDetailsGlobel.Columns.Add("Quantity");


            #endregion

            #region Set Distributor And System User info
            lblloginuser.Text = Gvlistuserdetails[0].Use_Name.ToString();
            lblcusname.Text = Gvdis_name;
            #endregion
        }

        private void dataGridView1_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
        {
            MessageBox.Show("oooooooo");
        }

        private void gdvselectedproduct_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
        {
            //if(e.RowCount>0)
            //{

            //    foreach (DataGridViewRow row in gdvselectedproduct.Rows)
            //    {
            //       string Lvproductname=row.Cells[0].ToString();
            //       MessageBox.Show("Product Name Is :" + Lvproductname);
            //    }

            
            //}
        }

        private void gdvselectedproduct_UserAddedRow(object sender, DataGridViewRowEventArgs e)
        {
            //MessageBox.Show("Show :) ");
        }

        private void gdvselectedproduct_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
            // Create a TextBox control.
            DataGridView tb = new DataGridView();
            this.Controls.Add(tb);
            tb.KeyPress += new System.Windows.Forms.KeyPressEventHandler(keypressed);
            

            if((7==e.ColumnIndex))          
            {
                MessageBox.Show("Show :)");
            }
        }

      

        
    }
}
